#!/bin/bash

file_name="$1"

if [ "$file_name" = "" ] || [ "$file_name" = "sys.img" ];then
    echo "create sys md5"
    echo "md5 name is sys_md5.txt"
    echo `md5sum sys.img | awk -F ' ' '{print $1}'` > sys_md5.txt
    exit
fi

if [ -e "$file_name" ];then
    echo "create $file_name md5"

    md5_name="sys_md5.txt"
    if [ "$file_name" = "upgrade.dtb" ];then
        md5_name="dtb_md5.txt"
    elif [ "$file_name" = "uImage" ];then
        md5_name="uImage_md5.txt"
    elif [ "$file_name" = "audio.img" ];then
        md5_name="audio_md5.txt"
    elif [ "$file_name" = "app.img" ];then
        md5_name="app_md5.txt"
    fi

    echo "md5 name is $md5_name"
    echo `md5sum $file_name | awk -F ' ' '{print $1}'` > "$md5_name"
else
    echo "file isn't exist"
fi

